package com.jbm.jbmsupplier.net;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import com.jbm.onehome.iface.GoodsClassEntity;
import com.jbm.onehome.iface.enums.RepairType;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by JBMhaier on 2017/8/9.
 * 报修页面Model
 */

public class FixModel {
    private Context context;
    private ArrayAdapter<String> mAdapter1;
    public int getGoods_code() {
        return goods_code;
    }

    private  int goods_code;

    public FixModel(Context context){
        this.context=context;
    }

    //获取种类类型
    public String parseType(int fixCategory){
        String str = null;
        switch (fixCategory){
            case 0:
                str= RepairType.save_danger.toString();
                break;
            case 1:
                str= RepairType.building_struct.toString();
                break;
            case 2:
                str= RepairType.water_proof.toString();
                break;
            case 3:
                str= RepairType.flue_dredging.toString();
                break;
            case 4:
                str= RepairType.room_repair.toString();
                break;
            case 5:
                str= RepairType.windows_repair.toString();
                break;
            case 6:
                str= RepairType.water_supply.toString();
                break;
            case 7:
                str= RepairType.circuit_repair.toString();
                break;
        }
        return str;
    }

    public void setDate(Spinner baoxiuFixCategory, final List<GoodsClassEntity> arr){
        if (arr==null){
            return;
        }
        mAdapter1 = new ArrayAdapter< String >(context, android.R.layout.simple_spinner_item, getDate(arr ));
        mAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        baoxiuFixCategory.setAdapter(mAdapter1);
        baoxiuFixCategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                goods_code = arr.get(position).getGcId();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }

    public  ArrayList<String>  getDate(List<GoodsClassEntity>arr ){
        ArrayList<String> att=new ArrayList<>();
        for (int i = 0; i <arr.size() ; i++) {
            att.add(arr.get(i).getGcName());
        }
       return att;

    }



}
